<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>客户列表</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<h3 align="center">客户列表</h3>
	<table border="1" cellspacing="0" width="70%" align="center">
		<tr>
			<th>客户姓名</th>
			<th>性别</th>
			<th>生日</th>
			<th>手机</th>
			<th>邮箱</th>
			<th>描述</th>
			<th>操作</th>
		</tr>
		<c:forEach items="${pb.beanList }" var="cstm">
			<tr>
				<td>${cstm.cname }</td>
				<td>${cstm.gender }</td>
				<td>${cstm.birthday }</td>
				<td>${cstm.cellphone }</td>
				<td>${cstm.email }</td>
				<td>${cstm.description }</td>
				<td>
					<a href="<c:url value='/demo3/CustomerServlet?method=preEdit&cid=${cstm.cid }'/>">编辑</a>
					<a href="<c:url value='/demo3/CustomerServlet?method=delete&cid=${cstm.cid }'/>" onclick="return confirm('确定要删除吗')">删除</a>
				</td>
			</tr>
		</c:forEach>
	</table>
	<br />
	<center>
		第${pb.pc }页/共${pb.tp }页
		<!-- <a href="<c:url value='/demo3/CustomerServlet?method=findAll&pc=1'/>">首页</a> -->
		<a href="${pb.url }&pc=1">首页</a>
		<c:choose>
			<c:when test="${pb.pc > 1 }">
				<a href="${pb.url }&pc=${pb.pc-1 }">上一页</a>
			</c:when>
			<c:otherwise>
				上一页
			</c:otherwise>
		</c:choose>
		
		<!-- 设置要显示页码列表的个数 -->
		<c:set var="plc" value="10"></c:set>
		<!-- 计算页码列表头尾 -->
		<c:choose>
			<c:when test="${pb.tp <= plc }">
				<c:set var="begin" value="1"></c:set>
				<c:set var="end" value="${pb.tp }"></c:set>
			</c:when>
			<c:otherwise>
				<c:set var="begin" value="${pb.pc - plc/2 + 1 }"></c:set>
				<c:set var="end" value="${pb.pc + plc/2 }"></c:set>
				<!-- 头溢出 -->
				<c:if test="${begin < 1 }">
					<c:set var="begin" value="1"></c:set>
					<c:set var="end" value="${plc }"></c:set>
				</c:if>
				<!-- 尾溢出 -->
				<c:if test="${end > pb.tp }">
					<c:set var="begin" value="${pb.tp - plc + 1 }"></c:set>
					<c:set var="end" value="${pb.tp }"></c:set>
				</c:if>
			</c:otherwise>
		</c:choose>
		<!-- 使用begin、end绘制页码列表 -->
		<c:forEach var="i" begin="${begin }" end="${end }">
			<c:choose>		
				<c:when test="${pb.pc != i }">
					<a href="${pb.url }&pc=${i }">${i }</a>
				</c:when>
				<c:otherwise>
					${i }
				</c:otherwise>
			</c:choose>
		</c:forEach>
		
		<c:choose>		
			<c:when test="${pb.pc < pb.tp }">
				<a href="${pb.url }&pc=${pb.pc + 1 }">下一页</a>
			</c:when>
			<c:otherwise>
				下一页
			</c:otherwise>
		</c:choose>
		<a href="${pb.url }&pc=${pb.tp }">尾页</a>
	</center>
</body>
</html>
